home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / russell / russell.lha / examples / psexpr_test.r < prev    next >
Text File  |  1989-12-29  |  615b  |  32 lines

  1. (* Compile psexpr.r first.                                    *)
  2. (* Test of binary tree data type.  Computes 2**m the hard way *)
  3. let
  4.     se == extern { "psexpr" };
  5.  
  6.     SEXPR == se[Short];
  7.          
  8.     x == Short$New[];
  9.     t == SEXPR$New[]
  10. in
  11.     t := SEXPR$nil;
  12.     x := get[FS];
  13.     do
  14.     x > 0 ==>
  15.         t := cons[t, t];
  16.         x := x - 1;
  17.     od;
  18.     let
  19.     Number_of_Leaves ==
  20.         func[ x: val SEXPR ]
  21.         {
  22.             if  null[x] ==>
  23.                 1    
  24.             #   else ==>
  25.                 Number_of_Leaves[car[x]] + Number_of_Leaves[cdr[x]]
  26.                     fi
  27.                 }
  28.     in
  29.     put[ Number_of_Leaves[t] ]; put["\n"]
  30.     ni
  31. ni
  32.